/*global module:false*/
module.exports = function(grunt) {
    'use strict';
    var _ = require('lodash');
    var ngTemplatesModule = {
      cwd: 'app/',
      src: 'js/pdfview/tpl/*.html',
      dest: 'app/js/pdfview/template.js',
      options: {
        bootstrap: function(module, script) {
          return 'define(["WebPDF"], function() {\n \
angular.module("' + module + '").run(["$templateCache", function($templateCache){ \n ' + script + '}]);\n });\n';
        },
        htmlmin: {
          collapseBooleanAttributes: true,
          collapseWhitespace: true,
          removeAttributeQuotes: true,
          removeComments: true,
          removeEmptyAttributes: true,
          removeRedundantAttributes: true,
          removeScriptTypeAttributes: true,
          removeStyleLinkTypeAttributes: true
        }
      }
    };


  // Project configuration.
  grunt.initConfig({
    // Task configuration.
    jshint: {
      options: {
        curly: true,
        eqeqeq: true,
        immed: true,
        latedef: true,
        newcap: true,
        noarg: true,
        sub: true,
        undef: true,
        unused: true,
        boss: true,
        eqnull: true,
        globals: {
          jQuery: true
        }
      },
      gruntfile: {
        src: 'Gruntfile.js'
      },
      lib_test: {
        src: ['lib/**/*.js', 'test/**/*.js']
      }
    },
    nodeunit: {
      files: ['test/**/*_test.js']
    },
    watch: {
      gruntfile: {
        files: '<%= jshint.gruntfile.src %>',
        tasks: ['jshint:gruntfile']
      },
      lib_test: {
        files: '<%= jshint.lib_test.src %>',
        tasks: ['jshint:lib_test', 'nodeunit']
      }
    },
    bower: {
      install: {
        options: {
          targetDir: './app/js/lib',
          layout: 'byComponent',
          install: true,
          verbose: false,
          cleanTargetDir: false,
          cleanBowerDir: false,
          bowerOptions: {}
        }
      }
    },
    karma: {
      unit: {
        configFile: 'test/karma.conf.js',
        singleRun: true
      }
    },   
	
	ngtemplates:{
		WebPDF: _.defaults({
      src: 'js/pdfview/tpl/*.html',
      dest: 'app/js/pdfview/template.js',   
    }, ngTemplatesModule),
		
		FormPlugin: _.defaults({	
			src: 'js/Plugins/Form/tpl/*.html',
			dest: 'app/js/Plugins/Form/template.js'
		}, ngTemplatesModule)
	},

  });

  // These plugins provide necessary tasks.
  grunt.loadNpmTasks('grunt-contrib-nodeunit');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-bower-task');
  grunt.loadNpmTasks('grunt-angular-templates');

  // Default task.
  grunt.registerTask('default', ['jshint', 'nodeunit']);
  grunt.registerTask('build', ['ngtemplates']);
};
